package com.shanghaiyimu.yimiyangche.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.adapter.MyWashListViewAdapter;
import com.shanghaiyimu.yimiyangche.bean.WashCarBean;

import java.util.ArrayList;
import java.util.List;

public class WashCarActivity extends AppCompatActivity{

    private ImageView back;
    private ListView  mListView;
    private View mHeadView;
    private WashCarBean washCarBean;
    private List<WashCarBean> data = null;
    private MyWashListViewAdapter adapter;
    private TextView carMode;
    private RelativeLayout quanchetiemo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wash_car);

        initData();
        initView();

    }

    private void initData() {

        data = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            washCarBean = new WashCarBean();
            washCarBean.setName("标准清洗"+i);
            data.add(washCarBean);
        }

    }

//    @Override
//    protected void onResume() {
//        super.onResume();
//        if (carModeName != null){
//            carMode.setText(carModeName+"  v ");
//        }
//    }

    private void initView() {

        carMode = (TextView) findViewById(R.id.wash_car_activity_tv_carmode);

        back = (ImageView) findViewById(R.id.wash_bar_img_back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        mListView = (ListView) findViewById(R.id.carMode_wash_lstView);
        mHeadView = LayoutInflater.from(this).inflate(R.layout.wash_head_view,null);
        mHeadView.setClickable(false);
        mListView.addHeaderView(mHeadView);

        adapter = new MyWashListViewAdapter(this,data);
        mListView.setAdapter(adapter);

        quanchetiemo = (RelativeLayout) mHeadView.findViewById(R.id.quanchetiemo);
        quanchetiemo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(WashCarActivity.this,GoodsListActivity.class);
                intent.putExtra("name","贴膜");
                startActivity(intent);
            }
        });

        View viewById = mHeadView.findViewById(R.id.relative_layout1);
        viewById.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(WashCarActivity.this,BiaoZhunWashCarActivity.class);
                startActivity(intent);
            }
        });


    }

    private int requestCode;
    public void carModeChoose(View view) {
        Intent intent = new Intent(this, CarModeChooseActivity.class);
        // 请求码的值随便设置，但必须>=0
        requestCode = 0;
        startActivityForResult(intent, requestCode);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        String carModeName = data.getStringExtra("mode");
        switch (resultCode){
            case 0:
                carMode.setText(carModeName+" ");
                break;
            default:
                break;
        }
    }

    //    public void getCarMode(String mode){
//        carModeName = mode;
//    }

}
